import java.util.Deque;
import java.util.LinkedList;

class MinStack {
    Deque<Integer> stack;
    Deque<Integer> minStack;

    public MinStack() {
        stack = new LinkedList<>();
        minStack = new LinkedList<>();
    }

    public void push(int val) {
        if(stack.isEmpty() && minStack.isEmpty()) {
            stack.push(val);
            minStack.push(val);
            return;
        }

        if(val <= minStack.peek()) {
            minStack.push(val);
        }
        stack.push(val);
    }

    public void pop() {
        if(stack.peek().compareTo(minStack.peek()) == 0) {
            minStack.pop();
        }
        stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}